package com.supor.aiot.mine.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.android.baseconfig.base.GlideApp;
import com.android.baseconfig.recyclerview.ByRecyclerView;
import com.supor.aiot.common.ui.view.gridlayout.adapter.CommAdapter;
import com.supor.aiot.common.ui.view.gridlayout.adapter.XBaseAdapter;
import com.supor.aiot.common.ui.view.gridlayout.adapter.XQuickViewHolder;
import com.supor.aiot.mine.R;
import com.supor.aiot.mine.bean.CookingMediaSelectBean;

import java.util.List;

/**
 * @author: zook
 * @date: 2021/10/18
 */
public class CookingCommXGraidAdapter extends CommAdapter<CookingMediaSelectBean> {
    private OnItemChildClickListener onItemChildClickListener;

    public CookingCommXGraidAdapter(Context context, List<CookingMediaSelectBean> data, int layoutId) {
        super(context, data, layoutId);
    }

    @Override
    public void convert(XQuickViewHolder holder, CookingMediaSelectBean item, int position) {
        switch (item.getItemType()) {
            case CookingMediaSelectBean.TYPE_ITEM_COVER:
                holder.getView(R.id.ll_upload_container).setVisibility(View.GONE);
                holder.getView(R.id.iv_cover).setVisibility(View.VISIBLE);
                holder.getView(R.id.fl_del).setVisibility(View.GONE);
                GlideApp.with(mContext).load(item.getPath())
                        .into((ImageView) holder.getView(R.id.iv_cover));
                break;
            case CookingMediaSelectBean.TYPE_ITEM_IMG:
                holder.getView(R.id.ll_upload_container).setVisibility(View.GONE);
                holder.getView(R.id.iv_cover).setVisibility(View.VISIBLE);
                holder.getView(R.id.fl_del).setVisibility(View.VISIBLE);
                GlideApp.with(mContext).load(item.getPath())
                        .into((ImageView) holder.getView(R.id.iv_cover));
                break;
            case CookingMediaSelectBean.TYPE_ITEM_VIDEO:
                holder.getView(R.id.ll_upload_container).setVisibility(View.GONE);
                holder.getView(R.id.iv_cover).setVisibility(View.VISIBLE);
                holder.getView(R.id.fl_del).setVisibility(View.VISIBLE);
                GlideApp.with(mContext).load(item.getPath())
                        .into((ImageView) holder.getView(R.id.iv_cover));
                break;
            case CookingMediaSelectBean.TYPE_ITEM_UPLOAD_IMG:
                holder.getView(R.id.ll_upload_container).setVisibility(View.VISIBLE);
                holder.getView(R.id.iv_cover).setVisibility(View.GONE);
                holder.getView(R.id.fl_del).setVisibility(View.GONE);
                holder.setText(R.id.tv_upload_title, "上传图片");
                holder.setBackgroundRes(R.id.iv_upload_action, R.mipmap.ic_media_camera);
                break;
            case CookingMediaSelectBean.TYPE_ITEM_UPLOAD_VIDEO:
                holder.getView(R.id.ll_upload_container).setVisibility(View.VISIBLE);
                holder.getView(R.id.iv_cover).setVisibility(View.GONE);
                holder.getView(R.id.fl_del).setVisibility(View.GONE);
                holder.setText(R.id.tv_upload_title, "上传视频");
                holder.setBackgroundRes(R.id.iv_upload_action, R.mipmap.ic_media_video);
                break;
        }
        if (null != onItemChildClickListener) {
            holder.getView(R.id.ll_upload_container).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onItemChildClickListener.onCLick(view, item, position);
                }
            });
            holder.getView(R.id.fl_del).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onItemChildClickListener.onCLick(view, item, position);
                }
            });
        }
    }

    public void setOnItemChildClickListener(OnItemChildClickListener onItemChildClickListener) {
        this.onItemChildClickListener = onItemChildClickListener;
    }

    public interface OnItemChildClickListener {

        void onCLick(View view, CookingMediaSelectBean item, int position);

    }
}
